package com.ylyl.langchain4j13chatrag01.controller;


import ai.djl.modality.nlp.embedding.TextEmbedding;
import com.ylyl.langchain4j13chatrag01.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class RAGController {

    @Resource
    private EmbeddingStore<TextSegment> embeddingStore;

    @Resource
    ChatAssistant chatAssistant;

    @GetMapping(value = "/rag/add")
    public String testAdd(){

        Document document = FileSystemDocumentLoader
                .loadDocument("D:\\student\\test.txt");
        EmbeddingStoreIngestor.ingest(document, embeddingStore);

        String result = chatAssistant.chat("00030是什么");

        System.out.println(result);

        return result;
    }
}
